#include "statusbarcontrols.h"
#include "ui_statusbarcontrols.h"
#include "transport.h"
#include "free-cube/logger.h"


StatusBarControls::StatusBarControls(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::StatusBarControls),
  sequencer_(NULL)
{
  ui->setupUi(this);
}

StatusBarControls::~StatusBarControls()
{
  delete ui;
}

void StatusBarControls::set_model (fc::AISequencer & seq) {
  sequencer_ = &seq;
  ui->btn_play->setChecked(sequencer_->is_playing());
  ui->btn_cycle->setChecked(sequencer_->is_cycling());
}

void StatusBarControls::refresh(int time_elapsed)
{
  Q_UNUSED (time_elapsed);
  ui->position->setText(QString("%1").arg(sequencer_->current_time()));
}

void StatusBarControls::on_btn_play_toggled(bool is_pressed){
  Q_ASSERT (sequencer_);
  if (sequencer_->is_cycling()) sequencer_->jump_to_locator(0);
  sequencer_->set_playing(is_pressed);
};

void StatusBarControls::on_btn_stop_pressed(){
  ui->btn_play->setChecked(false);
}

void StatusBarControls::on_btn_cycle_toggled(bool is_pressed){
  Q_ASSERT (sequencer_);
  sequencer_->set_cycling(is_pressed);
}
